package com.fh.wanandroid.ui.project.presenter;

import android.util.Log;

import com.fh.wanandroid.net.RetrofitHelper;
import com.fh.wanandroid.ui.mainpager.MainPagerContract;
import com.fh.wanandroid.ui.mainpager.bean.FeedArticleListData;
import com.fh.wanandroid.ui.project.bean.ProjectData;
import com.fh.wanandroid.ui.project.contract.ProjectContract;
import com.fh.wanandroid.utils.NetErrorUtil;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class ProjectPresenter extends  ProjectContract.Presenter{

    @Override
    public void getProjectData() {

        mCompositeDisposable.add(RetrofitHelper.createArticleApi().getProject()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ProjectData>() {
                    @Override
                    public void accept(ProjectData projectData) throws Exception {
//                        mView.refreshArticles(articleModel.getItems());
//                        mView.appendData(girlBean.getResults());

                        Log.e("ProjectPresenter","------------------ProjectPresenter projectData size:"+projectData.getData().size());
                        mView.getProjectClass(projectData);

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable t) throws Exception {
//                        mView.loadArticlesFail(NetErrorUtil.handleThrowable(t));
                        mView.loadDataFail(NetErrorUtil.handleThrowable(t));
                    }
                }));

    }
}
